package uk.ac.glasgow.demosocs.impl.ui;

import java.util.Set;

import uk.ac.glasgow.clui.CommandDescription;
import uk.ac.glasgow.clui.MinimumArguments;
import uk.ac.glasgow.clui.SystemCommand;
import uk.ac.glasgow.clui.SystemCommandException;
import uk.ac.glasgow.demosocs.Candidate;
import uk.ac.glasgow.demosocs.Election;
import uk.ac.glasgow.demosocs.VotingSystem;
import uk.ac.glasgow.demosocs.impl.ElectionImpl;

@MinimumArguments(0)
@CommandDescription("List all nominations for the currently selected user.")
public class GetNominationCommand extends SystemCommand<VotingSystem> {

	public GetNominationCommand(VotingSystem facade) {
		super(facade);
	}

	@Override
	public String processCommand(String[] arguments) throws SystemCommandException {

		String guid = facade.getCurrentUserGUID();
		if (guid == null)
			throw new SystemCommandException("No current user set.");

		String result = "EID \t Status\n";

		Set<Election> nominations = facade.getNominations();

		for (Election nomination : nominations) {
			for (Candidate e : nomination.getCandidates()) {
				if (e.getGUID().equals(guid))
					result += nomination.getEID() + "\tAccepted\n";
			}
		}

		for (Election election : nominations) {
			ElectionImpl impl = (ElectionImpl) election;
			
			for (Candidate e : impl.getUnapprovedCandidates()) {
				if (e.getGUID().equals(guid))
					result += impl.getEID() + "\tNot Accepted\n";
			}

		}

		return result;
	}

}
